package me.luraframework.commons.auth;

import lombok.Data;

import java.util.Optional;

@Data
public class UserContext {

    private final static ThreadLocal<UserContext> INSTANCE = new InheritableThreadLocal<>();

    private Long userId;
    private String username;

    public static String currentUsername() {
        return Optional.ofNullable(INSTANCE.get()).map(UserContext::getUsername).orElse("");
    }

    public static Long currentUserId() {
        return Optional.ofNullable(INSTANCE.get()).map(UserContext::getUserId).orElse(null);
    }
}
